import React from 'react';
import {WeaSearchGroup, WeaFormItem, WeaLocaleProvider, WeaCheckbox,WeaSelect } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import EType from './base/EType';
import ETitle from './base/ETitle';
import SynergySetting4Designer from './synergy/SynergySetting4Designer';
import EPortalBrowser from "./base/EPortalBrowser";
// 日历日程
export default class Content_MyCalendar extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            isShowLunarValue: this.props.isShowLunarDatas || '0',
            stylevalue: this.props.stylevalue || '1',
            stylename: this.props.stylename || '',
            styletype:this.props.styletype||'',
            defaultView:this.props.defaultView||'2',
            showtype:eval(this.props.defaultView) || 2,
            // showtype: eval(this.props.defaultView) || 3,
            isdoubleweek:this.props.isdoubleweek||1,
            types: [
                {value:getLabel('524156',"周视图"),key:2},
                {value:getLabel('524157',"双周视图"),key:4},
                {value:getLabel('524158',"月视图"),key:3},
            ]
        }
    }

    render() {
        const {hpid, eid, ebaseid, eShareLevel, synergyParams} = this.props;
        const {stype, pagetype, ispagedeal} = synergyParams;
        const {stylevalue, styletype, types, showtype,defaultView}=this.state;
        let {stylename,isdoubleweek,isShowLunarValue}=this.state;
        const CalendarStyle={
            defaultName:getLabel(523459,'视图切换-简约风格'),
        }

        stylename==""||parseInt(stylevalue)==1?stylename=CalendarStyle.defaultName:stylename;
        let customComponent = <div></div>;
        if (eShareLevel == '2') {
            customComponent = (
                <div>
                    {hpid < 0 && stype == 'wf' && pagetype == 'operat' && ispagedeal == '1' ? <span className="synergy-setting-btn" onClick={() => this.ss4d.onShow({...synergyParams, hpid, ebaseid, eid, isGlobal: true})}>{getLabel(17632	,'参数设置')}</span> : ''}
                </div>
            );
        }
        return (
            <div>
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@on2mv2`} title={getLabel(81711, '基本信息')} needTigger={true} showGroup={true} customComponent={customComponent}>
                    <SynergySetting4Designer ecId={`${this && this.props && this.props.ecId || ''}_SynergySetting4Designer@4qunq8`} ref={(ss4d) => this.ss4d = ss4d}/>
                    <EType ecId={`${this && this.props && this.props.ecId || ''}_EType@dm3asf`} ref="eType" value={this.props.eBaseName}/>
                    {this.props.eShareLevel == '2' ? <ETitle ecId={`${this && this.props && this.props.ecId || ''}_ETitle@6qynyh`} ref="eTitle" eid={this.props.eid} value={this.props.eTitle} {...this.props}/> : ''}
                    {this.props.eShareLevel == '2'?<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@8n2pea`} label={getLabel(522424,'日历日程样式') } labelCol={{span: 6}} wrapperCol={{span: 16}} >
                        {
                            <div style={{display: 'inline-block', width: '100%'}}>
                                <EPortalBrowser ecId={`${this && this.props && this.props.ecId || ''}_EPortalBrowser@iobrs2`}
                                value={stylevalue}
                                tabname={stylename}
                                tabstyle={stylevalue}
                                hasSearch={true} 
                                title={getLabel(522425,'选择日历日程样式') }
                                multiCheck={false}
                                isShow={true}
                                ebaseid={ebaseid}
                                api={'/api/portal/browserstyle/getCalendarStyle'}
                                style={{width: '54px', marginLeft: '15px', height: '30px', width: '100%'}}
                                onChange={(id, name,browsertype,doubleweek,defaultlunar,datas)=> {
                                    let sName=name;
                                    if(sName==""){
                                        sName=stylename
                                    }
                                    let sType=browsertype;
                                    if(sType==""){
                                        sType=styletype;
                                    }
                                    let sisdoubleweek=doubleweek;
                                    if(sisdoubleweek==''||sisdoubleweek==undefined){
                                        sisdoubleweek=isdoubleweek;
                                    }
                                    let sisdefaultlunar=defaultlunar;
                                    if(sisdefaultlunar==''||sisdefaultlunar==undefined){
                                        sisdefaultlunar='0'
                                    }
                                    this.setState({stylevalue : id, stylename: sName,styletype:sType,showtype:2,isdoubleweek:sisdoubleweek,isShowLunarValue:sisdefaultlunar})
                                }}
                                />
                            </div>
                        }
                    </WeaFormItem>:''}
                    {this.props.eShareLevel == '2'&&isdoubleweek==1&&
                        <WeaFormItem label={getLabel(524160,'选择默认视图')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                           <div style={{display: 'inline-block'}}>
                            <div style={{width: '200px'}}>
                            <WeaSelect
                                options={
                                    types.map((item) => {
                                        return {key: item.key, selected: false, showname: item.value};
                                    })
                                }
                                value={showtype}
                                onChange={value => {
                                    if(parseInt(value)==2){
                                        this.setState({showtype: types[0].key,defaultView:types[0].key});
                                    }else if(parseInt(value)==4){
                                        this.setState({showtype: types[1].key,defaultView:types[1].key});
                                    }else{
                                        this.setState({showtype: types[2].key,defaultView:types[2].key});
                                    }
                                }}
                                />
                            </div>
                            </div>
                        </WeaFormItem>
                    }
                    {this.props.eShareLevel == '2' ? <WeaFormItem label={getLabel(524159,'是否显示农历')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                        <WeaCheckbox display="switch" value={this.state.isShowLunarValue} onChange={value => this.setState({isShowLunarValue: value})}/>
                    </WeaFormItem> : ''}
                </WeaSearchGroup>
            </div>
        );
    }

    getSaveValues() {
        return {
            eContentTitle: this.refs['eTitle'] ? this.refs['eTitle'].getSaveValues() : this.props.eTitle,
            stylevalue: this.state.stylevalue,
            stylename: this.state.stylename,
            defaultView: this.state.defaultView,
            isdoubleweek:this.state.isdoubleweek,
            isShowLunarDatas: this.state.isShowLunarValue,
        };
    }
}